const mongoose = require('mongoose')
// 连接mongodb数据库
mongoose.connect('mongodb://127.0.0.1:27017/bilibili')

mongoose.connection.once('open',() => { 
    console.log('连接成功！')

    const bookSchema = new mongoose.Schema({
        name:String,
        author:String,
        price:Number,
        is_hot:Boolean
    })
    let bookModel = mongoose.model('novel',bookSchema)

    // 删除一条
    // bookModel.deleteOne({_id : '66c7ef84da22fdc4123c1a1a'}).then(res=>{
        // console.log('删除成功！')
    // }).catch(error=>{
        // console.log('删除失败！')
    // })
    bookModel.deleteMany({is_hot:false}).then((res) => { 
        console.log('删除成功:',res)
    }).catch(error=>{
        console.log('删除失败:',error)
    })



 })
mongoose.connection.on('close',() => { 
    console.log('关闭连接！')
 })